package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.impl.ShopingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userShopingCarttroller")
@Slf4j
@Api(tags = "购物车相关接口")
@RequestMapping("/user/shoppingCart")
public class ShopingCartController {
    @Autowired
    private ShopingCartService shopingCartService;
    @GetMapping("/list")
    @ApiOperation("获取购物车")
    public Result getlist(){
        List<ShoppingCart> list = shopingCartService.getlist();
        return Result.success(list);
    }

    @PostMapping("/add")
    @ApiOperation("新增菜品或套餐")
    public Result add(@RequestBody ShoppingCartDTO dto){
        shopingCartService.add(dto);
        return Result.success();
    }
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result clean(){
        shopingCartService.clean();
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车中的一个商品")
    public Result sub(@RequestBody ShoppingCartDTO dto){
        shopingCartService.sub(dto);
        return Result.success();
    }

}
